package com.example.writting.ui.words

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.example.writting.R
import com.example.writting.model.FlowStep

class FlowAdapter : RecyclerView.Adapter<FlowAdapter.FlowViewHolder>() {
    private var steps: List<FlowStep> = emptyList()

    fun updateSteps(newSteps: List<FlowStep>) {
        steps = newSteps
        notifyDataSetChanged()
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): FlowViewHolder {
        val view = LayoutInflater.from(parent.context).inflate(R.layout.item_flow_step, parent, false)
        return FlowViewHolder(view)
    }

    override fun onBindViewHolder(holder: FlowViewHolder, position: Int) {
        holder.bind(steps[position], position == steps.size - 1)
    }

    override fun getItemCount(): Int = steps.size

    inner class FlowViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        private val stepTitle: TextView = itemView.findViewById(R.id.stepTitle)
        private val stepSubtitle: TextView = itemView.findViewById(R.id.stepSubtitle)
        private val arrow: ImageView = itemView.findViewById(R.id.arrow)

        fun bind(step: FlowStep, isLast: Boolean) {
            stepTitle.text = step.title
            stepSubtitle.text = step.subtitle
            arrow.visibility = if (isLast) View.GONE else View.VISIBLE
        }
    }
} 